﻿using System;

namespace DO.DreamOnTrader.Quote
{
	public class KBar : IComparable
    {
        #region ========變數

        /// <summary>
        /// K開盤價
        /// </summary>
        public float OpenPrice { get; protected set; }
        
        /// <summary>
        /// K最高價
        /// </summary>
        public float HPrice { get; protected set; }
        
        /// <summary>
        /// K最低價
        /// </summary>
        public float LPrice { get; protected set; }
        
        /// <summary>
        /// k收盤價
        /// </summary>
        public float ClosePrice { get; protected set; }
        
        /// <summary>
        /// k成交量
        /// </summary>
        public uint Vol { get; protected set; }
        
        /// <summary>
        /// k結束時間
        /// </summary>
        public DateTime Ktime { get; protected set; }


		/// <summary>
		/// 當下ktime的近月交割月份
		/// </summary>
		public string CloseMonth
		{
			get
			{
				DateTime _d = Tick.getCloseDate(Ktime);
				return _d.Year.ToString() + _d.Month.ToString().PadLeft(2, '0');
			}
		}

        #endregion

        public KBar(float _open, float _high, float _low, float _close, uint _vol, DateTime _ktime)
        {
            OpenPrice = _open;
			HPrice = _high;
			LPrice = _low;
			ClosePrice = _close;
			Vol = _vol;
			Ktime = _ktime;
        }

		public override string ToString()
		{
			string[] nn = { Ktime.ToString("yyyy/MM/dd hh:mm:ss"), " OPEN:" + OpenPrice, " HIGH:" + HPrice, " LOW:" + LPrice, " CLOSE:" + ClosePrice, " VOL:" + Vol };
			return string.Join(",", nn);
		}


		#region IComparable 成員

		public int CompareTo(object obj)
		{
			KBar tobj = (KBar)obj;
			return this.Ktime.CompareTo(tobj.Ktime);
		}

		#endregion
	}
}
